package sketch.labels.nodes;

import java.awt.Color;
import java.util.ArrayList;

import sketch.labels.Tree;

public class Node{
	private String name;
	private Color color;
	
	private Tree tree;
	
	public Node(String name,Tree tree){
		this.name=name;
		this.tree=tree;
		this.color=Color.BLACK;
	}
	
	public String getName(){
		return this.name;
	}
	
	public void setName(String name){
		this.name=name;
	}
	
	public Color getColor(){
		return this.color;
	}
	
	public void setColor(Color color){
		this.color=color;
	}
	
	public boolean isLeaf(){
		boolean result=true;
		for(int i=2;i<tree.size();i++){
			ChildNode node=(ChildNode)tree.getNode(i);
			if(node.getParent().getName().equals(this.getName())){
				result=false;
				break;
			}
		}
		return result;
	}
	
	public ArrayList<ChildNode> getChildren(){
		ArrayList<ChildNode> result=null;
		if(!this.isLeaf()){
			result=new ArrayList<ChildNode>();
			for(int i=2;i<tree.size();i++){
				ChildNode node=(ChildNode)tree.getNode(i);
				if(node.getParent().getName().equals(this.getName())){
					result.add(node);
				}
			}
		}
		return result;
	}
	
	public String toString(){
		return this.getName();
	}
}
